#include <iostream>
#include <map>
#include <functional>
#include <memory>

class Product {
public:
    virtual void use() = 0;
    virtual ~Product() {}
};

class ProductA : public Product {
public:
    void use() override {
        std::cout << "Using Product A" << std::endl;
    }
};

class ProductB : public Product {
public:
    void use() override {
        std::cout << "Using Product B" << std::endl;
    }
};

class ProductFactory {
private:
    std::map<std::string, std::function<std::unique_ptr<Product>()>> registry;

public:
    void registerProduct(const std::string& name, std::function<std::unique_ptr<Product>()> creator) {
        registry[name] = creator;
    }

    std::unique_ptr<Product> createProduct(const std::string& name) {
        if (registry.find(name) != registry.end()) {
            return registry[name]();
        }
        std::cout << "Product not found" << std::endl;
        return nullptr;
    }
};

int main() {
    ProductFactory factory;

    // Register products
    factory.registerProduct("ProductA", []() { return std::make_unique<ProductA>(); });
    factory.registerProduct("ProductB", []() { return std::make_unique<ProductB>(); });

    // Create and use a product
    auto product = factory.createProduct("ProductA");
    if (product) {
        product->use();
    }

    return 0;
}